package com.efast.dmom.mes.controller;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.efast.dmom.mes.bean.EquipSpareOutbound;
import com.efast.dmom.mes.bean.ResultBean;
import com.efast.dmom.mes.entity.EquipSpareOutboundEntity;
import com.efast.dmom.mes.entity.base.IModificationFlags;
import com.efast.dmom.mes.service.EquipSpareOutboundService;

/**
 * to achieve the sprareOutbound to add, delete, update and query
 * 
 * @author wj
 * @date 2020/4/23
 *
 */
@Controller
@RequestMapping(value = "/sprareOutbound")
public class EquipSpareOutboundController {
	
	@Autowired
	private EquipSpareOutboundService equipSpareOutboundService;
	
	@RequestMapping(value = "/operateBySpareOutBound")
	public @ResponseBody ResultBean operateBySpareOutBound(@RequestBody EquipSpareOutbound equipSpareOutbound) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (equipSpareOutbound.getModificationFlag() == IModificationFlags.NEW) {
			return equipSpareOutboundService.save(equipSpareOutbound);
			// Judge to update
		} else if (equipSpareOutbound.getModificationFlag() == IModificationFlags.MODIFIED) {
			return equipSpareOutboundService.update(equipSpareOutbound);
			// Judge to delete
		} else if (equipSpareOutbound.getModificationFlag() == IModificationFlags.DELETED) {
			return equipSpareOutboundService.delete(equipSpareOutbound);
		}
		return resultBean;
	}
	
	@RequestMapping(value = "/affirmSpareOutBound")
	public @ResponseBody ResultBean affirmSpareOutBound(@RequestBody List<EquipSpareOutboundEntity> spareList) {
		return equipSpareOutboundService.affirmSpareOutBound(spareList);
	}
	
	@RequestMapping(value = "/operateBySpareOutBoundItem")
	public @ResponseBody ResultBean operateBySpareOutBoundItem(@RequestBody EquipSpareOutbound equipSpareOutbound) {
		ResultBean resultBean = new ResultBean(true, ' ');
		// Judge to add
		if (equipSpareOutbound.getModificationFlag() == IModificationFlags.NEW) {
			return equipSpareOutboundService.saveItem(equipSpareOutbound);
			// Judge to update
		} else if (equipSpareOutbound.getModificationFlag() == IModificationFlags.MODIFIED) {
			return equipSpareOutboundService.updateItem(equipSpareOutbound);
			// Judge to delete
		} else if (equipSpareOutbound.getModificationFlag() == IModificationFlags.DELETED) {
			return equipSpareOutboundService.deleteItem(equipSpareOutbound);
		}
		return resultBean;
	}

}
